<template>
    <div class="mask">
        <div class="TMB-warp">
            <div class="titler">
                <span class="font-w fs16" style="font-weight: 700;">{{ title }}</span>
                <i class="el-icon-close" @click="CloseTables"></i>
            </div>
            <div class="middle">
                <div class="router">
                    <el-breadcrumb separator-class="el-icon-arrow-right">
                        <el-breadcrumb-item v-for="(item, index) in projectRouteData" :key="index"
                            @click.native="GetBookRelaAssFileApi(item.id, 'del')">
                            {{ item.name }}
                        </el-breadcrumb-item>
                    </el-breadcrumb>
                </div>
                <ux-grid class="ux-table" ref="singleTable" :data="prposTabelData" :header-cell-style="{
                    color: 'rgba(0, 0, 0, 0.85)',
                    fontSize: '14px',
                    textAlign: 'left',
                    fontWeight: 'bold',
                    padding: 0,
                    height: '32px',
                    background: 'rgb(244,245,246)'
                }" :cell-style="{
                    color: 'rgba(96,98,102,1)',
                    fontSize: '14px',
                    textAlign: 'left',
                    padding: 0,
                    height: '32px',
                }" :checkbox-config="{
                    showHeader: false,
                    checkMethod: checkMethod
                }" @selection-change="handleSelectionChange" @current-change="handleCurrentChange"
                    highlight-current-row v-loading="loading" element-loading-spinner="el-icon-loading"
                    element-loading-background="#f8f8f8" :element-loading-text="$t('message.bhView.loading')"
                    height="500">
                    <template slot="empty"> No data </template>
                    <ux-table-column type="checkbox" width="40" align="center" title=""
                        v-if="type != 'portray' && type != 'rouHou' && type != 'device'">
                    </ux-table-column>
                    <ux-table-column property="label" title="名称" tooltip align="center">

                        <template slot-scope="scope">
                            <el-tooltip class="item" effect="dark" :content="scope.row.name" placement="top">
                                <div style="display: flex;justify-items: center;cursor: pointer;text-overflow: ellipsis;overflow: hidden;"
                                    @click="scope.row.fileType == 2 ? GetBookRelaAssFileApi(scope.row.id, 'add') : ''">
                                    <i class="iconfont tableIcon" v-if="scope.row.fileType == 2">&#xe823;</i>
                                    <i class="iconfont tableIcon" v-else>&#xe62b;</i>
                                    <span>{{ scope.row.name }}{{ scope.row.ext.trim() == '' ? '' : '.' }}{{
                                        scope.row.ext
                                    }}</span>
                                </div>
                            </el-tooltip>
                        </template>
                    </ux-table-column>
                    <!-- <ux-table-column property="label" title="サイズ">

                        <template slot-scope="scope">
                            <p>{{ scope.row.size }} KB</p>
                        </template>
                    </ux-table-column>
                    <ux-table-column property="label" title="更新日時">

                        <template slot-scope="scope">
                            <p>{{ scope.row.modifyTime }}</p>
                        </template>
                    </ux-table-column>
                    <ux-table-column property="label" title="所有者">

                        <template slot-scope="scope">
                            <p>{{ scope.row.userName }}</p>
                        </template>
                    </ux-table-column> -->
                </ux-grid>
                <div class="footer">
                    <span></span>
                    <div>
                        <el-button type="default" size="mini" style="font-size: 14px;"
                            @click="CloseTables">Cancel</el-button>
                        <el-button type="primary" size="mini" style="font-size: 14px; width: 75.59px !important;"
                            @click="okFn">OK</el-button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import BASE from '@/utils/base'
import { GetBookRelaAssFile, GetResOfferBookAssociationAssFile, GetResOfferPhotoRelaFile, getThckDeterminator, GetDrawAss, getProcessFileList } from '@/api/api'
import eventBus from "@/eventBus/bus";

export default {
    name: "RightTabelShow",
    props: ["type", "title", "ClsType"],
    data() {
        return {
            prposTabelData: [
                // {
                //     test: 111
                // }
            ],
            loading: false,
            selectionArr: [],
            cnt: 0,
            LineNo: '',
            projectRouteData: [
                {
                    name: 'Disk',
                    id: '0'
                }
            ]

        };
    },
    components: {},
    watch: {},
    methods: {
        //表格方法，同种通知可以査看，不同图纸不可以选择
        checkMethod({ row }) {

            return row.fileType == 1;

        },
        handleSelectionChange(e) {
            let isSingleFlg = false;
            console.log(this.type);
            if (this.type == 'basic') {
                // res = await GetBookRelaAssFile(dataJson);
                isSingleFlg = false;
            } else if (this.type == 'of') {
                // res = await GetResOfferBookAssociationAssFile(dataJson);
                isSingleFlg = false;
            } else if (this.type == 'portray') {
                // res = await GetResOfferPhotoRelaFile(dataJson);
                isSingleFlg = false;
            } else if (this.type == 'rouHou') {
                // res = await GetResOfferBookAssociationAssFile(dataJson);
                isSingleFlg = true;
            } else if (this.type == 'draw') {
                // res = await GetDrawAss(dataJson);
                isSingleFlg = true;
            } else if (this.type == 'device') {
                // res = await getProcessFileList(dataJson);
                isSingleFlg = true;
            }
            // 单选
            if (isSingleFlg) {
                if (e.length > 1) {
                    e.forEach((i, v) => {
                        if (v == e.length - 1) {
                            this.$refs.singleTable.toggleRowSelection([
                                {
                                    row: i,
                                    selected: true
                                }
                            ])
                        } else {
                            this.$refs.singleTable.toggleRowSelection([
                                {
                                    row: i,
                                    selected: false
                                }
                            ])
                        }
                    })
                }
                this.selectionArr = [e[e.length - 1]];
            } else {
                this.selectionArr = e;
            }

        },
        handleCurrentChange(val) {
            console.log(val);
            if (this.type == 'portray' || this.type == 'rouHou' || this.type == 'device') {
                this.selectionArr = [val];
            }
        },
        okFn() {
            console.log(this.selectionArr);
            if (this.selectionArr.length == 0) {
                return
            }

            if (this.type == 'device') {
                this.selectionArr[0].projectRouteData = this.projectRouteData;
                eventBus.$emit('deviceGetTableRow', this.selectionArr);
                this.$emit('close');
                return
            }
            this.$emit("getResponse", this.selectionArr);
            this.$emit('close');
        },
        CloseTables() {
            this.$emit('close')
        },
        // id 请求路径的，type=》'add'进入目录添加路径，'del'进入路径，削除之后路径
        async GetBookRelaAssFileApi(id = '0', type = 'default') {

            if (type == 'add') {
                let filterArr = this.prposTabelData.filter(item => item.id == id);
                this.projectRouteData = [...this.projectRouteData, ...filterArr];
            }
            if (type == 'del') {
                let index = this.projectRouteData.findIndex(obj => obj.id === id);
                if (index !== -1) {
                    this.projectRouteData.splice(index + 1);
                }
            }

            this.loading = true;
            this.prposTabelData = [];
            this.prposTabelData.length = 0;
            let dataJson = {
                PltCode: this.$store.state.pltCode,
                ParentID: id,
                isReportFolder : false,
            }

            // タイトルに報告書フォルダ指定時のみ
            if(this.title === "報告書フォルダ"){
                dataJson.isReportFolder = true;
            }

            let res;
            console.log(this.type);
            if (this.type == 'basic') {
                res = await GetBookRelaAssFile(dataJson);
            } else if (this.type == 'of') {
                res = await GetResOfferBookAssociationAssFile(dataJson);
            } else if (this.type == 'portray') {
                res = await GetResOfferPhotoRelaFile(dataJson);
            } else if (this.type == 'rouHou') {
                res = await GetResOfferBookAssociationAssFile(dataJson);
            } else if (this.type == 'draw') {
                dataJson.ClsType = this.ClsType;
                res = await GetDrawAss(dataJson);
            } else if (this.type == 'device') {
                res = await getProcessFileList(dataJson);
            }
            this.loading = false;

            if (res.data.code != 0) {
                return
            }
            this.prposTabelData = res.data.data;
        },
    },
    created() { },
    mounted() {
        this.GetBookRelaAssFileApi();
    },
    beforeDestroy() { },
    destroyed() { },
    updated() {
        // 使用querySelectorAll选中所有带有.elx-cell--checkbox类的元素
        var elements = document.querySelectorAll('.elx-cell--checkbox');

        // 遍历这些元素  
        elements.forEach(function (element) {
            // 修改每个元素的title属性  
            element.setAttribute('title', '');
        })
    },
};
</script>

<style lang="scss" scoped>
.mask {
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9999;


}

.TMB-warp {
    width: 800px;
    background: rgb(255, 255, 255);
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%);
    box-shadow: 0px 12px 48px 16px rgba(0, 0, 0, 0.05),
        0px 9px 28px 0px rgba(0, 0, 0, 0.08), 0px 6px 16px -8px rgba(0, 0, 0, 0.15);
    z-index: 100;

    .titler {
        height: 43px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 13px 24px;
        border-bottom: 1px solid #F0F0F0FF;

        i {
            cursor: pointer;
        }
    }

    .middle {
        padding: 13px 24px;

        .router {
            padding-bottom: 13px;
        }

        .title {
            display: flex;
            margin-bottom: 13px;

            .seach {
                width: 24px;
                height: 24px;
                border-radius: 4px;
                border: 1px solid #d9d9d9;
                display: flex;
                align-items: center;
                justify-content: center;
                cursor: pointer;
                margin-right: 12px;
            }

            .form-ipt {
                height: 24px;

                ::v-deep .el-input__inner {
                    width: 197px;
                    height: 24px;
                    background: #fff;
                }
            }
        }

        ::v-deep .ux-table * {
            border: none;
        }

        ::v-deep .elx-table {
            border: 1px solid #00000026;
        }

        .table {
            border-bottom: 1px solid red !important;
        }

        .footer {
            height: 43px;
            // background-color: #EDEEEFFF;
            // border: 1px solid #00000026;
            // border-top: none;
            font-size: 14px;
            margin-top: 15px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 4px;
        }
    }
}

.iconfont {
    font-size: 24px;
    margin: 0 8px;
}

.tableIcon {
    font-size: 20px;
    margin: 0 4px;
}

.el-breadcrumb__item {
    cursor: pointer;
}
</style>
